package com.diandi.messages.manager.impl.email;

import com.diandi.messages.bean.email.MessageEmail;
import com.diandi.messages.manager.email.MessageEmailManager;
import com.diandi.messages.mapper.email.MessageEmailMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created by jiangquan1900 on 2017/9/22.
 */
@Component
public class MessageEmailManagerImpl implements MessageEmailManager {

    @Autowired
    private MessageEmailMapper emailMapper;

    @Override
    public Integer insertEmail(Map<String, String> paramMap) {
        MessageEmail email = new MessageEmail();
        email.setPassCode(paramMap.get("passCode"));
        if (paramMap.containsKey("userId") && StringUtils.isNotBlank(paramMap.get("userId"))){
            email.setUserId(Long.parseLong(paramMap.get("userId")));
        }
        email.setBusinessId(paramMap.get("businessId"));
        email.setEmail(paramMap.get("toAddress"));
        email.setMerchantNo(paramMap.get("merchantNo"));
        email.setMessageBatchTrade(paramMap.get("tradeNo"));
        email.setMessageTrade(paramMap.get("tradeNo"));
        email.setRequestMsg(paramMap.toString());
        email.setStatus(2);
        return emailMapper.insertMessageEmail(email);
    }

    @Override
    public Integer updateEmail(Map<String, Object> paramMap) {
        return emailMapper.updateMessageEmail(paramMap);
    }
}
